# -*- coding: utf-8 -*-
"""
逻辑回归鸢尾花
Created on Sat Apr 21 10:45:37 2018

@author: Allen
"""
import numpy as np
import matplotlib.pyplot as plt
from sklearn import datasets

iris = datasets.load_iris()

X = iris.data
y = iris.target

# 取出前两个分类，同时维度保留前两维
X = X[y<2, :2]
y = y[y<2]

# 绘制图像
plt.scatter( X[y==0, 0], X[y==0,1], color = "red" )
plt.scatter( X[y==1, 0], X[y==1,1],color = "blue" )
plt.show()

from playML.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split( X, y, seed = 666 )

# 使用逻辑回归
from playML.LogisticRegression import LogisticRegression
log_reg = LogisticRegression()
log_reg.fit( X_train, y_train )

# 打印出正确率
print( log_reg.score( X_test, y_test ) ) # 1.0

# 打印出测试集概率
print( log_reg.predict_proba( X_test ) )
'''
[ 0.92972035  0.98664939  0.14852024  0.17601199  0.0369836   0.0186637
  0.04936918  0.99669244  0.97993941  0.74524655  0.04473194  0.00339285
  0.26131273  0.0369836   0.84192923  0.79892262  0.82890209  0.32358166
  0.06535323  0.20735334]
'''

# 打印出预测结果
print( log_reg.predict( X_test ) )
# [1 1 0 0 0 0 0 1 1 1 0 0 0 0 1 1 1 0 0 0]

